package plataforma.cih.campos;

import java.util.Date;

import org.zkoss.zul.Space;
import org.zkoss.zul.Span;

public class CampoDataHora extends Span {

	CampoData campoData = new CampoData();

	CampoHora campoHora = new CampoHora();

	public CampoDataHora() {
		montarComponente();
		Date value = new Date();
		setValue(value);

	}

	private void montarComponente() {

		this.appendChild(campoData);
		this.appendChild(new Space());
		this.appendChild(campoHora);

	}

	public Date getValue() {

		Date value = campoData.getValue();
		Date dataHora = campoHora.getValue();

		if (value != null) {
			// coloco os minutos e horas na data

			if (dataHora != null) {
				value.setHours(dataHora.getHours());
				value.setMinutes(dataHora.getMinutes());
			} else {
				// zero a hora e minutos
				value.setHours(0);
				value.setMinutes(0);

			}

		}

		return value;
	}

	public void setConstraint(String constraint){
		campoData.setConstraint(constraint);
		campoHora.setConstraint(constraint);
		
	}
	public void setValue(Date value) {

		campoData.setValue(value);
		campoHora.setValue(value);
	}

	public boolean isValid() {

		return campoData.isValid() && campoHora.isValid();
	}

}

